package com.jhhc.StormSurgeForecast.StormSurge.Uitl;

import org.springframework.stereotype.Component;

@Component
public class VariableUtil {

    //etaMax 计算方法 (波峰高度)规范曲线拟合
    public String calculationEtaMax(double H,double d){// H 波高  d 水深
        double d1 = H / d;
        double eta1 = -0.3536 * Math.pow(d1,2);
        double eta2 = 0.6407 * d1;
        double etaMax = H * (eta1 + eta2 + 0.5022);
//        System.out.println(H);
//        System.out.println(d);
//        System.out.println(d1);
//        System.out.println(eta1);
//        System.out.println(eta2);
//        System.out.println(etaMax);
        return String.format("%.2f",etaMax);
    }
    //etaMax 计算方法 (波峰高度)二阶Stokes波理论分析
    public String calculationEtaMax2(double H,double d,double m_wave_t){// H 波高  d 水深
        VariableUtil variableUtil = new VariableUtil();
        double L = Double.parseDouble(variableUtil.calculationL(d,m_wave_t));
        double eta1 = H / 2;
        double e1 = Math.PI * Math.pow(H,2);
        double e2 = 2 * L;
        double eta2 = e1 / e2;
        double t1 = 2 * Math.PI * d;
        double t2 = t1 / L;
        double eta3 = Math.cosh(Math.toRadians(t2));
        double a1 = 4 * Math.PI * d;
        double a2 = a1 / L;
        double eta4 = Math.cosh(Math.toRadians(a2)) + 2;
        double b1 = 2 * Math.PI * d;
        double b2 = b1 / L;
        double b3 = Math.sinh(Math.toRadians(b2));
        double eta5 = 4 * Math.pow(b3,3);
        double eta6 = eta3 * eta4 / eta5;
        double dta = eta1 + eta2 * eta6;
        System.out.println(String.format("%.2f",dta));
        return String.format("%.2f",dta);
    }
    //deltah 计算方法(净空高度)
    public String calculationDeltaH(double z){ //z 水位
        double deltah = 4.85 - z;
        return String.format("%.2f",deltah);
    }

    //d 计算方法(水深)
    public String calculationD(double z){
        double d = z - (-10);
        return String.format("%.2f",d);
    }

    //L 计算方法(波长)m_wave_t波周期   D水深
    public String calculationL(double D,double m_wave_t){
        double a=1;//波浪初始赋值
        double m_wave_1;
        if (D > 0 && m_wave_t > 0) {
            for (int i = 0; i < 10; i++) {
                m_wave_1 = 9.81 / 2 / 3.1415 * m_wave_t * m_wave_t
                        * (Math.exp(2 * Math.PI / a * D) - Math.exp(-2 * Math.PI / a * D))
                        / (Math.exp( 2 * Math.PI / a * D) + Math.exp( -2 * Math.PI / a * D));
                a = (a + m_wave_1) / 2;
            }
        }
        return String.format("%.2f",a);
    }

    //waveDirection 波向桥轴线夹角判断方法(波向桥轴线夹角)
    public double calculationWaveDirection(double waveDirection){
        if (waveDirection >= 0 && waveDirection < 90) {
            return 90 - waveDirection;
        }else if (waveDirection >= 90 && waveDirection < 180) {
            return waveDirection - 90;
        } else if (waveDirection >= 180 && waveDirection < 270) {
            return 270 - waveDirection;
        }else if (waveDirection >= 270 && waveDirection < 360) {
            return waveDirection - 270;
        }else {
            return -1;
        }
    }

    //Kξ 墩型系数取值  1青州航道桥主墩  2过渡桥墩 3九州航道桥主墩 4江海航道桥主墩 5非通航孔桥墩
    public double calculationK(int count){
        switch (count){
            case 1:
                return 2.64;
            case 2:
            case 3:
                return 2.70;
            case 4:
                return 2.60;
            case 5:
                return 2.48;
            default:
                break;
        }
        return 0;
    }
    //B1 桥墩计算宽度  1青州航道桥主墩  2过渡桥墩 3九州航道桥主墩 4江海航道桥主墩 5非通航孔桥墩
    public double calculationB1(int count){
        switch (count){
            case 1:
                return 30.5;
            case 2:
            case 3:
                return 22;
            case 4:
                return 23.5;
            case 5:
                return 7.1;
            default:
                break;
        }
        return 0;
    }

    //λ  波陡计算方法
    public String calculation(double H,double L){//H波高  L波长
        double lambda = H/L;
        return String.format("%.2f",lambda);
    }


    //水流流速的计算方法
    public String currentSpeed(double u,double v){
        double ls = Math.sqrt(u*u + v*v);

        return String.format("%.2f",ls);

    }

    public int typeJudge(String type){
        int t = 0;
        switch (type){
            case "非通航孔桥墩1":
            case "非通航孔桥墩2":
                return t = 5;
            case "九州航道桥主墩":
                return t = 3;
            case "青州航道桥过渡墩":
                return t = 2;
            case "青州航道桥主墩":
                return t = 1;
            case "江海航道桥主墩":
                return t = 4;
            default:
                break;
        }
        return t;
    }
    /**
     *
     * m  斜坡坡度m  2
     * @param H1  波高H1%
     * @param L  波长L  需计算
     * @return 破波参数 ξ1%
     */
    public String kexi1(double H1,double L){
        //double kexi = 1.0 / 2.0 / Math.sqrt(H1 / L);
        return String.format("%.2f",1.0 / 2.0 / Math.sqrt(H1 / L));
    }

    /**
     *  EL  平台高程  3
     * @param WL  水位（潮位）
     * @return 平台上水深dB
     */
    public String dB(double WL){
        return String.format("%.2f",WL - 3);
    }

    /**
     * 堤顶高程CL  8
     * @param WL 水位（潮位）
     * @return 超高Rc
     */
    public String Rc(double WL){
        return String.format("%.2f",8 - WL);
    }

    /**
     *
     *  B  平台宽度B  12
     *   斜坡坡度m  2
     * @param Hs 有效波高Hs
     * @param dB 平台上水深dB  需计算
     * @return 平台折减系数Kb
     */
    public String Kb(double Hs,double dB){
        //double Kb = 1 - (B / (B + m * Hs + 6 * Hs)) * (1 - 0.5 * dB / Hs);
        if (1 - (12 / (12 + 2 * Hs + 6 * Hs)) * (1 - 0.5 * dB / Hs) < 0.6){
            return "0.60";
        }else {
            return String.format("%.2f",1 - (12 / (12 + 2 * Hs + 6 * Hs)) * (1 - 0.5 * dB / Hs));
        }
    }

    /**
     *
     * @param bc  坡肩宽度bc  5.7
     * @return  坡肩折减系数Kc
     */
    public String Kc(double bc){
        //double kc = 0.0015 * Math.pow(bc,3) - 0.0109 - Math.pow(bc,2) - 0.1135 * bc + 1;
        return String.format("%.2f",0.0015 * Math.pow(bc,3) - 0.0109 * Math.pow(bc,2) - 0.1135 * bc + 1);
    }

}
